<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //100%
    var canPlaceFlowers = function(flowerbed, n) {
        const len = flowerbed.length;
        if(n==0)return true;
        if(len==1){
            if(flowerbed[0]==0)return true;
            else return false;
        }
        let num = 0;
        if(flowerbed[0]==0 && flowerbed[1]==0){
            num++;
            flowerbed[0]=1;
        }
        for(let i=1; i<len-1; i++){
            if(flowerbed[i]==0 && flowerbed[i-1]==0 && flowerbed[i+1]==0){
                num++;
                flowerbed[i]=1;
            }
        }
        if(flowerbed[len-1]==0 && flowerbed[len-2]==0)num++;
        return num>=n;
    };
    let flowerbed = [0],n=1;
    console.log(canPlaceFlowers(flowerbed, n));
    
</script>
</html>